// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import VueRouter from 'vue-router'
import Vuex from 'vuex'
import axios from 'axios'

axios.defaults.withCredentials = true;

import 'lib-flexible'
import echarts from 'echarts'
import URL from './util/url'
import 'echarts/dist/echarts.min.js'
import 'font-awesome/css/font-awesome.min.css'
// import jquery from 'jquery'
// import 'jquery/dist/jquery.min.js'
import $ from 'jquery'

import N3Components from 'N3-components'
import 'N3-components/dist/index.min.css'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import Vuetify from 'vuetify'
import 'vuetify/dist/vuetify.min.css'
import Vuelidate from 'vuelidate'
import vueGridLayout from 'vue-grid-layout';

import App from './App'
import store from './store'
import util from './util/util'
import resource from './resource'
import {routers} from './router'
import Bus from './util/bus'
import './util/directives'
import {simpleGet,get, patch, post, post1, put, remove, delete1,postAdvanced} from './util/axios'
import {delCookie, getCookie, setCookie} from './util/cookie'
import {formatTime, dateFormat} from './util/date'
import globalConstant from "./util/global";
import  mapBoxGl from 'mapbox-gl'
import jsPlumb from 'jsplumb'
// import { toLineChartData, toPieChartData, toBarChartData, toBarbarChartData, toGuageChartData } from './views/layout/changeChart'


Vue.use(VueRouter);
Vue.use(Vuex);
Vue.use(ElementUI);
Vue.use(Vuetify);
Vue.use(N3Components);
Vue.use(Vuelidate);
Vue.use(echarts);
Vue.use(vueGridLayout);


// Vue.prototype.$Msg = message;
Vue.prototype.Mapbox = mapBoxGl;
// Vue.prototype.jsPlumb = jsPlumb;


Vue.prototype.$jsPlumb = jsPlumb.jsPlumb;
Vue.prototype.$Bus = Bus;
Vue.prototype.$URL = URL;
Vue.prototype.$axios = {
    simpleGet,
    get,
    post,
    post1,
    patch,
    put,
    postAdvanced,
    remove,
    delete1
};//定义axios标签
Vue.prototype.$cookie = {
    getCookie,
    setCookie,
    delCookie
};//定义cookie标签
Vue.prototype.$date = {
    formatTime,
    dateFormat,
};
// Vue.prototype.$changeChart = {
//     toLinechartData: toLineChartData,
//     toPiechartData: toPieChartData,
//     toBarchartData: toBarChartData,
//     toBarbarChartData: toBarbarChartData,
//     toGuageChartData: toGuageChartData
//
// };
Vue.prototype.$globalConstant = globalConstant;
//定义服务器url
Vue.prototype.$serverUrl = "http://10.2.40.51:9500/dbfg/";

Vue.config.productionTip = false;

function guardRoute(to, from, next) {
    if (sessionStorage.getItem("userid") != null) {
        next();
        return true;
    } else {
        Bus.$emit("alertModalParams", {
            alertType: "error",
            alertDescription: "该页面需要先登录~"
        });
        next({
            path: from.path
        });
        return false;
    }
}

// 路由配置
const RouterConfig = {
    mode: 'hash',
    routes: routers
};
const router = new VueRouter(RouterConfig);

router.beforeEach((to, from, next) => {
    let currentPageTitle = to.meta.title;
    if (to.matched.some(m => m.meta.requireAuth)) {
        // if (!guardRoute(to, from, next)) {
        //     currentPageTitle = from.meta.title;
        // }
    } else {
        next();
    }
    util.title(currentPageTitle)//设置网页标题
});

router.afterEach((to, from, next) => {
    window.scrollTo(0, 0)
});

/* eslint-disable no-new */
new Vue({
    el: '#app',
    store,
    router,
    resource,
    template: '<App/>',
    components: {App}
});

